﻿<UserControl x:Class="Plugins.UserControls.DateSelector"

             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             
             xmlns:Converters="clr-namespace:Utils.Wpf.Converters;assembly=Utils"
             xmlns:UserControls="clr-namespace:Plugins.UserControls" Background="#1F1F1F"
             
             mc:Ignorable="d"
             
             d:DesignHeight="130" 
             d:DataContext="{d:DesignInstance Type=UserControls:DateSelectorVM}" >

    <UserControl.Resources>
        <ResourceDictionary>
            <Converters:BooleanNotConverter x:Key="BooleanNotConverter" />
            <Converters:IsNotNullConverter x:Key="IsNotNullConverter" />
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\PluginTheme.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

		<TextBlock Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Text="Date Selection" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="6" />

        <CheckBox Grid.Row="1" Grid.Column="1" Margin="0,3,3,3" Content="Use All  Days" IsChecked="{Binding UseAllDays}" >
            <CheckBox.ToolTip>
                <StackPanel>
                    <TextBlock Foreground="Black" FontWeight="Bold" Text="Use all days" />
                    <TextBlock Foreground="Black" Text="The engine will use all the available days containing data of the selected stock." />
                </StackPanel>
            </CheckBox.ToolTip>
        </CheckBox>
        <TextBlock Grid.Row="2" Grid.Column="0" Margin="3,3,6,3" Text="Start" VerticalAlignment="Center" />
        <TextBlock Grid.Row="3" Grid.Column="0" Margin="3,3,6,3" Text="End" VerticalAlignment="Center" />
        <DatePicker Grid.Row="2" Grid.Column="1" IsTodayHighlighted="True" VerticalAlignment="Center" Background="Transparent" FirstDayOfWeek="Monday" IsEnabled="{Binding UseAllDays, Converter={StaticResource BooleanNotConverter}}" SelectedDate="{Binding StartDate, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}" DisplayDateStart="{Binding FirstStartDate}" DisplayDateEnd="{Binding LastStartDate}" BorderThickness="0" >
            <DatePicker.ToolTip>
                <StackPanel>
                    <TextBlock Foreground="Black" FontWeight="Bold" Text="OperationStartDate Date" />
                    <TextBlock Foreground="Black" Text="The first day of the range of days used by the engine to execute the strategy with." />
                </StackPanel>
            </DatePicker.ToolTip>
        </DatePicker>
        <Border Grid.Row="3" Grid.Column="1" IsEnabled="{Binding StartDate, Converter={StaticResource IsNotNullConverter}}" >
            <!-- The border is used to have a second IsEnabled -->
            <DatePicker IsTodayHighlighted="True" VerticalAlignment="Center" Background="Transparent" FirstDayOfWeek="Monday" IsEnabled="{Binding UseAllDays, Converter={StaticResource BooleanNotConverter}}" SelectedDate="{Binding EndDate, ValidatesOnDataErrors=True, ValidatesOnExceptions=True, NotifyOnValidationError=True}" DisplayDateStart="{Binding FirstEndDate}" DisplayDateEnd="{Binding LastEndDate}" BorderThickness="0" >
                <DatePicker.ToolTip>
                    <StackPanel>
                        <TextBlock Foreground="Black" FontWeight="Bold" Text="ForcedCloseTimeDate Date" />
                        <TextBlock Foreground="Black" Text="The first day of the range of days used by the engine to execute the strategy with." />
                    </StackPanel>
                </DatePicker.ToolTip>
            </DatePicker>
        </Border>
    </Grid>
</UserControl>
